﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细管理</title>
    <#include "../common/link.ftl">

    <script>
        $(function () {

            //新增或编辑按钮的点击事件
            $('.btn-input').click(function () {
                //先清除之前模态框的数据
                $('#editModal input').val('');
                //通过选择器 找到ul下面的<a>超链接中 被选中的便签
                var $li = $('ul>a.active').length;//根据是否选中 选中的才有active样式
                console.log($li); //有选中 $li的值为1 每选中为0
                //判断 如果没有选中 返回警告信息,终止
                if ($li === 0) {
                    $.messager.alert("警告", "请先选中左侧字典目录,再新增或者编辑");
                    return;
                } else {
                    //如果有选中
                    //把当前目录的名称 设置到 字典明细模态框的第一行 目录名称中
                    $('#parentName').val($("a[data-id=${qo.parentId!}]").text());
                    //把当前选中的选中目录的id 也赋值给字典明细模态框中的 隐藏域 parentId
                    $('#parentId').val(${(qo.parentId)!});

                }


                //给编辑显示的模态框回显数据
                var json = $(this).data("json");
                if (json) {
                    $("#editForm input[name=id]").val(json.id);
                    $("#editForm input[name=title]").val(json.title);
                    $("#editForm input[name=sequence]").val(json.sequence);
                }
                //打开模态框
                $('#editModal').modal('show');
            })

            //保存操作
            $('.btn-insert').click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm").ajaxSubmit(function (data) {
                    handlerMessage(data)
                })
            })

        })

    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="systemDictionaryItem"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row">
                    <div class="col-md-3">
                        <div class="panel panel-default">
                            <div class="panel-heading">字典目录</div>
                            <div class="panel-body">
                                <ul class="list-group">
                                    <#list systemDictionaries as dic>
                                        <a href="/systemDictionaryItem/list.do?parentId=${(dic.id)!}"
                                           data-id="${dic.id}"
                                           class="list-group-item systemDictionary ${(dic.id==(qo.parentId)!-1)? string('active','')}">
                                            ${dic.title}
                                        </a>
                                    </#list>
                                    <script>
                                        //$("a[data-id=${qo.parentId!}]").addClass("active");
                                    </script>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-9">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list.do" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <!--带上qo的parentId 去后台 解决左侧目录条件丢失问题--->
                            <input type="hidden" value="${(qo.parentId)!}" name="parentId">
                            <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>标题</th>
                                    <th>序号</th>
                                    <th>操作</th>
                                </tr>
                            <#list result.list as systemDictionaryItem>
                                <tr>
                                    <td>${systemDictionaryItem_index+1}</td>
                                    <td>${systemDictionaryItem.title!}</td>
                                    <td>${systemDictionaryItem.sequence!}</td>
                                    <td>
                                        <a href="#"
                                           class="btn btn-info btn-xs btn-input"
                                           data-json='${systemDictionaryItem.json}'>
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>
                                    </td>
                                </tr>
                            </#list>
                            </table>
                            <!--分页-->
                            <#include "../common/page.ftl">
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<!---部门编辑模态框--->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate.do" method="post"
                      id="editForm">
                    <input type="hidden" value="" name="id">
                    <input type="hidden" class="form-control" name="parentId" id="parentId">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">目录：</label>
                        <div class="col-sm-6">
                            <input type="text" style="text-align:left;" class="form-control" name="parentName"
                                   id="parentName" value="" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" value="" placeholder="请输入标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence" value="" placeholder="请输入序号,若不填会自动增长">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-insert">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
